package com.xunce.xcworkservice.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xunce.xcworkservice.dto.LoginDto;
import com.xunce.xcworkservice.entity.Account;
import com.xunce.xcworkservice.response.R;
import com.xunce.xcworkservice.service.AccountService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.subject.Subject;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author yanlong.guo
 */
@RestController
@RequiredArgsConstructor
@Validated
@Slf4j
@Tag(name = "首页登录信息")
public class IndexController {

    private final AccountService accountService;

    @GetMapping("/test")
    @Operation(summary = "测试方法", description = "测试描述")
    public String test(){
        log.info("这是一个调试日志");
        log.error("这是一个错误日志");
        log.debug("这是一个debug日志");
        log.warn("这是一个warn日志");
        return "hello java24";
    }

    @GetMapping("/page")
    @Operation(summary = "分页方法", description = "测试描述")
    public R<Page<Account>> page(){
        // 创建分页对象
        Page<Account> page = new Page<>(1, 20);
        accountService.page(page);
        return R.success(page);
    }

    @GetMapping("/permission")
    @RequiresPermissions("getPermission")
    @Operation(summary = "权限方法", description = "权限测试")
    public R<String> permission(){
        return R.success("获取权限成功");
    }
}
